package com.ch.recycleviewdinddemo

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.ch.recycleviewdinddemo.databinding.ItemLayoutBinding

class MyAdapter(private var listData: List<Idol>) : RecyclerView.Adapter<MyAdapter.MyViewHolder>() {


    inner class MyViewHolder(itemLayoutBinding: ItemLayoutBinding) :
        RecyclerView.ViewHolder(itemLayoutBinding.root) {
        var itemBinding: ItemLayoutBinding = itemLayoutBinding
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val itemLayoutBinding: ItemLayoutBinding = DataBindingUtil.inflate(
            LayoutInflater.from(parent.context),
            R.layout.item_layout,
            parent,
            false
        )
        return MyViewHolder(itemLayoutBinding)
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val idol = listData[position]
        holder.itemBinding.idol = idol
    }

    override fun getItemCount(): Int {
        return listData.size
    }
}